package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.CityPlay;
import cn.wolfcode.trip.base.mapper.CityPlayMapper;
import cn.wolfcode.trip.base.query.CityplayQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ICityPlayService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：大攻略业务层
 *
 * @package: cn.wolfcode.trip.base.service.impl
 * @author: Patch
 * @date: 2019/5/23 22:59
 * 总结:
 */
@Service
public class CityPlayServiceImplImpl implements ICityPlayService {
    @Autowired
    private CityPlayMapper cityPlayMapper;

    @Override
    public PageInfo<CityPlay> query(CityplayQueryObject qo) {

        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(),qo.getOrderBy());
        List<CityPlay> list = cityPlayMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void saveOrUpdate(CityPlay cityPlay) {
        if (cityPlay.getId() != null) {
            cityPlay.setCreadTime(new Date());
            cityPlayMapper.updateByPrimaryKey(cityPlay);
        } else {
            cityPlay.setCreadTime(new Date());
            cityPlayMapper.insert(cityPlay);
        }
    }

    @Override
    public CityPlay get(Long id) {
        return cityPlayMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<CityPlay> listAll(Integer state) {
        return cityPlayMapper.selectAll();
    }
}
